package com.isay.frameworklib.utils;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.View;

/**
 * Created by cywu4 on 2018/8/30.
 */

public class AnimUtils {

    /**
     * rotation动画
     */
    public static void rotationCenter(View v) {
        ObjectAnimator ra = ObjectAnimator.ofFloat(v, "rotation", 0f, 360f);
        ra.setDuration(1800);
        ra.start();
    }

    /**
     * rotation动画
     */
    public static void rotationCenter(View v, int duration) {
        ObjectAnimator ra = ObjectAnimator.ofFloat(v, "rotation", 0f, 360f);
        ra.setDuration(duration);
        ra.start();
    }


    /**
     * alpha动画
     */
    public static void alpha(View v) {
        ObjectAnimator fadeAnim = ObjectAnimator.ofFloat(v, "alpha", 0f, 1f);
        fadeAnim.setDuration(300);
        fadeAnim.start();
    }

    /**
     * alpha动画
     */
    public static void alpha(View view, int duration, float fromAlpha, float toAlpha) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(view, "alpha", fromAlpha, toAlpha);
        animator.setDuration(duration);
        animator.start();
    }


    /**
     * alpha动画
     */
    public static void scale(View view, int duration) {
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 1.2f, 1f);
        scaleX.setDuration(duration);
        scaleX.start();
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 1.2f, 1f);
        scaleY.setDuration(duration);
        scaleY.start();
        AnimatorSet anim = new AnimatorSet();
        anim.play(scaleX).with(scaleY);
    }


    /**
     * scaleWidthRotation动画
     */
    public static void scaleWidthRotation(View view, int duration) {
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 1.3f, 1f);
        scaleX.setDuration(duration);
        scaleX.start();
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 1.3f, 1f);
        scaleY.setDuration(duration);
        scaleY.start();
        ObjectAnimator ra = ObjectAnimator.ofFloat(view, "rotation", 0f, 360f);
        ra.setDuration(duration);
        ra.start();
        AnimatorSet anim = new AnimatorSet();
        anim.play(scaleX).with(scaleY).with(ra);
    }


}
